const HtmlWebpackPlugin = require('html-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const webpack = require('webpack');
const path = require('path');

module.exports = {
    entry: './src/index.js',
    externals:{
        'react': {
            root: "React",
            commonjs: "react",
            commonjs2: "react",
            umd: "react"
        },
        "react-dom": {
            root: "ReactDOM",
            commonjs: "react-dom",
            commonjs2: "react-dom",
            umd: "react-dom"
        },
        "react-router-dom": {
            root: "ReactRouterDOM",
            commonjs: "react-router-dom",
            commonjs2: "react-router-dom",
            umd: "react-router-dom"
        },
        'lodash' : {
            root: "_", // 指向全局变量
            commonjs: "lodash",
            commonjs2: "lodash",
            umd: "lodash"
        },
        'antd': {
            root: "antd",
            commonjs: "antd",
            commonjs2: "antd",
            umd: "antd"
        }
    },
    output: {
        filename: 'bundle.js',
        path: path.resolve(__dirname, 'dist'),
        publicPath: "/wandu/",
        libraryTarget: 'umd'
    },
    devtool: 'inline-source-map',
    devServer: {
        contentBase: './dist',
        hot: true,
        proxy: {
            '/makeUp': {
                target: "http://www.zhflybird.com",
                changeOrigin: true
            }
        }
    },
    module: {
        rules: [
            {
                test: /\.js$/,
                exclude: /node_modules/,
                use: {
                    loader: "babel-loader"
                }
            },
            {
                test: /\.s[ac]ss$/i,
                use: [
                  // Creates `style` nodes from JS strings
                  'style-loader',
                  // Translates CSS into CommonJS
                  'css-loader',
                  // Compiles Sass to CSS
                  'sass-loader',
                ],
            },
            {
                test: /\.(png|jpg|gif|jpeg)$/,
                use: [
                  {
                    loader: 'url-loader',
                    options: {
                      limit: 8192
                    }
                  }
                ]
            },
            {
                test: /\.(png|jpg|gif)$/,
                use: [
                  {
                    loader: 'file-loader',
                    options: {}
                  }
                ]
            }
        ]
    },
    plugins: [
        new HtmlWebpackPlugin({
            filename: 'index.html',
            template: 'index.html'
        }),
        new CopyWebpackPlugin({
            patterns: [
                {
                    from: __dirname + '/src/public',
                    to: __dirname + '/dist/public'
                }
            ]
        }),
        new webpack.NamedModulesPlugin(),
        new webpack.HotModuleReplacementPlugin()
    ],
    resolve: { 
        extensions: ['.js', '.jsx', '.json'] 
    }
};